home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 5961 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.9 KB

  1. Path: rover.ucs.ualberta.ca!alberta!diego
  2. From: diego@cs.ualberta.ca (Diego Novillo)
  3. Newsgroups: comp.lang.c++
  4. Subject: Problems extending an existing class library
  5. Date: 7 Feb 1996 17:29:56 GMT
  6. Organization: Computing Science, U of Alberta, Edmonton, Canada
  7. Message-ID: <4fanik$ltq@scapa.cs.ualberta.ca>
  8. NNTP-Posting-Host: charron.cs.ualberta.ca
  9.  
  10. We are developing a compiler using a code restructuring tool that
  11. provides classes for all the basic components of a program: Functions,
  12. Statements, Expressions, Types, Symbols and their corresponding
  13. sub-classes.
  14.  
  15. Now, we would like to create new sub-classes to specialize the existing
  16. classes and the first impulse was to inherit from them because the
  17. specialization was clearly an "is-a" relation.
  18.  
  19. This system parses the source code and builds a special file which
  20. contains the annotated parse tree of the program. All the objects reside
  21. on this binary file and the memory objects are just pointers to
  22. different portions of the file. As a result, the memory objects are just
  23. pointers to C data structures which hold the real implementation of the
  24. system (This class library is a wrapper around the old C
  25. implementation).
  26.  
  27. Since the base classes don't have constructors, we cannot build our own
  28. memory objects because our constructors cannot call the base class
  29. constructors to initialize the parent class.
  30.  
  31. We got around the problem by using a "has-a" relation. That is, each of
  32. our classes has a pointer to the "parent" class and each time we create
  33. a new object we just initialize this pointer.
  34.  
  35. We don't like this option too much, but we don't see another way around
  36. the problem. Modifying the original classes is not an option either, the
  37. system is large and we don't have much time to mess around with it.
  38.  
  39. Does anyone have a suggestion on how to work around this problem? Has
  40. anyone faced this problem before? How did you solve it?
  41.  
  42. Thank you.
  43.  
  44. Diego.
  45.  
  46.  
  47.